<?php 
	session_start(); 
	if(!isset($_SESSION['username']))
		header("Location:login.php");
?>
<html>
	<head>
	<title>WARPTracker</title>
	<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
	<script type="text/javascript" src="js/jquery-ui-1.8rc2.custom.min.js"></script>
	<link type="text/css" href="css/redmond/jquery-ui-1.8rc2.custom.css" rel="stylesheet" />	
	<script type="text/javascript" src="js/jquery.validate.js"></script>
	<script type="text/javascript" src="js/jquery.tablesorter.js"></script>
	<link type="text/css" href="css/date.css" rel="stylesheet" />	
	<link type="text/css" href="css/tabs.css" rel="stylesheet" />	
	<link type="text/css" href="css/style.css" rel="stylesheet" />	
	<script type="text/javascript">
	jQuery.validator.setDefaults({
	debug: true,
	success: "valid"
	});;

	$(function() {
		$("#tabs").tabs();
	});
	
	

	</script>
	</head>
	<body onload="initialize();">
	<script id="staticjs" type="text/javascript" src="js/viewaccount.js.php?unit=b7">

	</script>
	
<script type="text/javascript">
	

function init2(){
	$("#units").addClass("centercontent");
	$("#units").hide();
	$("#units2").html("");
	$("#accountForm").html("");
	$("#accountForm2").html("");
	$("#financeForm").html("");
	$("#financeForm2").html("");
	$("#addpaymentform").html("");

	$("#units2").html("<img src='gifs/indicator.gif' />Loading...");
	$("#units2").load("ajax/tabs/units.php", function(){
		$("#units").show();
		  $(".occupied, .unoccupied").click(function () {
		  unit = $(this).html();
		  $("#units").hide();
		   $("#units2").fadeOut("slow", function(){
			
				$("#units").show();
				$("#units2").load("ajax/templates/viewaccount.php?unit="+unit,function(){
				$("#units").removeClass("centercontent");
				$("#units2").fadeIn('slow');
					viewAccount();
					viewFinancialInfo();
					$("#addpaymentform").dialog('destroy');
					
							$("#addpaymentform").dialog({
						modal: true,
						resizable: false,
						width:250,
						autoOpen: false,
						show: "blind",
						hide: "explode",
						buttons: {
							Close : function() {
								$(this).dialog('close');
									$("#addpaymentform").html("");
									$("#units2").load("ajax/templates/viewaccount.php?unit="+unit,function(data){
										viewAccount();
										viewFinancialInfo();
									});	

								
							},

						}
					});
					
					
				  });
		   
		   });
		   
		   
	
		});
		
		
		
		$(".occupied").hover(function () {
			$(this).removeClass("occupied");
			  $(this).addClass("occupied2");
			}, function () {
			  $(this).removeClass("occupied2");
			  $(this).addClass("occupied");
			});
			
			$(".unoccupied").hover(function () {
			$(this).removeClass("unoccupied");
			  $(this).addClass("unoccupied2");
			}, function () {
			  $(this).removeClass("unoccupied2");
			  $(this).addClass("unoccupied");
			});
			
			
			
			
	});

}



function init3(){
	//$("#units2").html("");
	$("#requests").html("<img src='gifs/indicator.gif' />Loading...");
	$("#requests").load("ajax/tabs/requests.php", function(){
		viewRequestsList();
	});
}

function init4(){
	//$("#units2").html("");
	$("#inactive").html("<img src='gifs/indicator.gif' />Loading...");
	$("#inactive").load("ajax/tabs/inactive.php",function(){
			$("#inactivetable").tablesorter(			
			{
				widgets: ['zebra'],
				headers: { 
            // assign the secound column (we start counting zero) 
					3: { 
						// disable it by setting the property sorter to false 
						sorter: false
					} 
				} 
			}
			
			); 
	});
}

	function init5(){
		$("#reports").html("<img src='gifs/indicator.gif' />Loading...");
		$("#reports").load("ajax/tabs/reports.php",function(){
			
		});
	}

	
	var details;
	unit="B7";
	function viewRequestsList(){
		$("#requestsList").html("<img src='gifs/indicator.gif' />");
		$("#requestsList").load('controllers/ViewRequestController.php?mode=1',function(data) {
		  details=data;
		  displayRequestsList();
		});
	}
	function displayRequestsList(){
		$("#requestsList").html(details);
		$("input:button", "#requestsList").button();
	}
	
	function viewRequest(id1){
			$("#request").dialog({	
			modal: true,
			resizable: false,
			show: "slide",
			hide: "explode",
			buttons: {
				Close : function() {
					$(this).dialog('close');
				}
			}
		});
	$("#request").html("<img src='gifs/indicator.gif' />");
		$.post('controllers/ViewRequestController.php',{ 
		id:id1
		}, function(data) {
			details=data;
			displayRequestDetails();
		});
	}
	
	function displayRequestDetails(){
		$("#request").html(details);
	}
	function deleteRequest(){
		//alert(100);
		$("#deleteDialog").html("Are you sure you want to delete this request?");
			$("#deleteDialog").dialog({
				resizable: false,
				modal: true,
				position: 'top',
				buttons: {
					Cancel: function() {
						$(this).dialog('close');
					},
					'Delete Request	': function() {
						//stopContract();
						deleteRequests();
						
						$(this).dialog('close');
					}
				}
			});
	}
	
	function deleteRequests(){
		var i=0;
		var boxes="";
		while($("#box"+i).val()!=undefined){
			if($("#box"+i).is(':checked')){
				boxes += $("#box"+i).val();
				boxes += ",";
			}
			i++;
		}
		$("#requestsList").html("<img src='gifs/indicator.gif' />");
		$("#request").html("");
		$.post('controllers/DeleteRequestController.php',{
		ids:boxes
		}, function(data) {
			$("#requestsList").html("");
			$("#requestsList").load('controllers/ViewRequestController.php?mode=1',function(data) {
		  details=data;
		  displayRequestsList();
		});
			$("#request").html(data);
		});
	}
	
	function initialize(){
		$.ajaxSetup({cache: false});
			$("#exit").dialog({
				resizable: false,
				autoOpen:false,
				modal: true,
				position: 'top',
				close: function() { exit2();}
			});
			$("div").click(function (){
				isAdmin();
			});
	}
	var username="<?php echo $_SESSION['username'];?>";
	function isAdmin(){
		$.get("ajax/isAdmin.php", function(data){
		  // alert(data);
		  temp=data;
		  $.get("ajax/username.php", function(data){
		//  alert(data);
			   if(temp==666||username!=data){
					exit();
			   }
			});
			
		 });
	}

	
	
	function exit2(){
		window.location = "login.php";
	}

	function exit(){
		$('#exit').html('You are not logged in. Click <a href="login.php">here</a> to log in.');
		$('#exit').dialog('open');
	}
	

	</script>

<div class="demo">
<img src="images/header2.png"/>

<div id="tabs">
	<ul>
		<li><a href="#tabs-1">Home</a></li>
		<li><a href="#account">Account</a></li>
		<?php if($_SESSION['username']=="admin"){?>
		<li><a href="#units" onclick="init2();">Units</a></li>
		<?php }?>
		<li><a href="#requests" onclick="init3();">Requests</a></li>
		<?php if($_SESSION['username']=="admin"){?>
		<li><a href="#reports" onclick="init5();">Reports</a></li>
		<li><a href="#inactive" onclick="init4();">Inactive Contracts</a></li>
		<?php }?>
	</ul>
	<div id="contentdiv">
	<div id="tabs-1">
		<p id="welcome">Whitehouse Apartments Rental and Payment Tracker</p>
	</div>
	<div id="account">
			<a href="#" class="logoutlink" onclick="logout();">Log Out</a>
	<?php if($_SESSION['username']=="admin"){?>
			<h2>Account</h2>
			<div id="changePasswordForm3" title="Change Password"></div>
			<div id="changePasswordForm2" title="Change Password"></div>
		<a href="#" onclick="recoverPassword();">Recover Password</a><br /><br />
		<a href="#" onclick="changeAdminPassword();">Change Password</a><br /><br />
	<?php }?>

		<div id="recover" title="Recover Password"></div>
		<div id="logout" title="Logout"></div>
		<?php if($_SESSION['username']!="admin"){?>
			<script type="text/javascript">
					
				viewUnitAccount();

			</script>
			<div id="units2"></div>
		<div id="addpaymentform" title="Add Payment"></div>
		<div id="accountForm"></div>
		
		<div id="accountForm2" title="Edit Account Information"></div>
		<div id="financeForm"></div>
		<div id="financeForm2" title="Edit Financial Information"></div>
		<?php }?>
	</div>
	<div id="units">
		<?php if($_SESSION['username']=="admin"){?>
		<div id="units2"></div>
		<div id="addpaymentform" title="Add Payment"></div>
		<div id="accountForm"></div>
		<div id="accountForm2" title="Edit Account Information"></div>
		<div id="financeForm"></div>
		<div id="financeForm2" title="Edit Financial Information"></div>
		<div id="contractForm" title="Start Contract"></div>
		<?php }?>
	</div>
	<div id="requests"></div>
	<div id="reports"></div>
	<div id="inactive"></div>
	<div id="exit" title="Unauthorized"></div>
	</div>
</div>

</div><!-- End demo -->
	<div id="footer">
		Copyright &copy; 2010 Maskman Group<br />
		CMSC 128 AB-7L
	</div>
	</body>
</html>